var LottOBJ = function (o) {
    var conf = {
        obj: '',
        cover: '',
        count: 0,
        position: '',
        complete: function () { }
    };
    conf = $.extend(conf, o);
    conf.cover.hide();
    var pos = [], timer = null, spd = 100, curr = 0, round = 0;
    for (var i = 0; i < conf.position.split(',').length; i++) {
        var s = conf.position.split(',')[i];
        pos.push({ left: parseInt(s.split('_')[0]), top: parseInt(s.split('_')[1]) });
    }
    if (pos.length != conf.count) return;
    this.startRoll = function (n) {
        if (typeof (n) != 'number' && n > pos.length) n = 0;
        spd = 100;
        round = Math.ceil(Math.random() * 4) + 1;
        conf.cover.show().css({ left: pos[curr].left, top: pos[curr].top });
        timer = setTimeout(function () { roll(n); }, spd);
    };
    function roll(e) {
        clearTimeout(timer);
        if (curr == pos.length - 1) {
            if (round > 0) {
                round--;
                curr = 0;
            }
        } else
            curr++;
        conf.cover.css({ left: pos[curr].left, top: pos[curr].top });
        if (curr == e && round == 0) {
            setTimeout(conf.complete, 500);
            return;
        }
        if (round == 0) spd += 80;
        timer = setTimeout(function () { roll(e); }, spd);
    }
};